cmake_minimum_required(VERSION 3.18)
project(ACLStudy C CXX)

include(ExternalProject)

# External project for SCons-built submodule A
ExternalProject_Add(
    ACL
    SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/ComputeLibrary
    CONFIGURE_COMMAND ""
    BUILD_COMMAND scons toolchain_prefix=/opt/aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu- -C ${PROJECT_SOURCE_DIR}/third_party/ComputeLibrary
        Werror=1  debug=0  neon=1 opencl=0 os=linux openmp=1 cppthreads=0 arch=armv8.2-a fixed_format_kernels=1 build=cross_compile -j16
    INSTALL_COMMAND ""
)

string(APPEND CMAKE_CXX_FLAGS "-march=armv8.2-a+fp16")

file(GLOB TEST_SRCS ${PROJECT_SOURCE_DIR}/*.cpp)
foreach(TEST_SRC ${TEST_SRCS})
    get_filename_component(file_name_we ${TEST_SRC} NAME_WE)
    add_executable(${file_name_we} ${TEST_SRC})
    add_dependencies(${file_name_we} ACL)
    target_include_directories(${file_name_we} PRIVATE
        ${PROJECT_SOURCE_DIR}/third_party/ComputeLibrary
        ${PROJECT_SOURCE_DIR}/third_party/ComputeLibrary/include
    )
    file(GLOB ACL_LIBS ${PROJECT_SOURCE_DIR}/third_party/ComputeLibrary/build/*.so)
    target_link_libraries(${file_name_we} PRIVATE ${ACL_LIBS})
endforeach()

